<template>
  <DataList :cate="cate" :cols="cols" skipExcelNumber="3" :name="name"
  :excelHeader="excelHeader"/>
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import linq from "linq";
import { addJnjd, deleteJnjd, updateJnjd, getJnjd,bulkAddJnjd } from "@/api/职业技能鉴定机构.js";
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A4-3职业技能鉴定机构表",
      name:"4.3 职业技能鉴定机构",
      excelHeader:{B3:"职业技能鉴定站（所）全称",G4:"社会",H4:"在校生",C3:"鉴定内容",C4:"工种/证书名称(全称)",D4:"等级",E3:"建立单位",E4:"级别",F4:"部门",G3:"鉴定数（人天）"},
      cols: [
        { label: "职业技能鉴定站(所)全称", prop: "JGMC" },
        { label: "鉴定内容", prop: "职业技能鉴定机构_鉴定内容",
        data:[
            { label: "工种/证书名称(全称)", prop: "ZSMC" },
            { label: "等级", prop: "XZ_JDDJ" },
        ] },
        { label: "建立单位", prop: "职业技能鉴定机构_建立单位",
        data:[
            { label: "级别", prop: "XZ_JLDWJB" },
            { label: "部门", prop: "XZ_SQDW" },
        ] },
        { label: "鉴定数(人天)", prop: "职业技能鉴定机构_鉴定数",
        data:[
            { label: "社会", prop: "SHJDRC" },
            { label: "在校生", prop: "ZXSJDRC" },
        ] },
      ]
    };
  },
  methods: {
    getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
        sums[0]="合计"
         sums[6]= "鉴定站:"+linq.from(list).distinct("$.JGMC").count();
          sums[7]= "证书数:"+linq.from(list).count("$.ZSMC");
         sums[11]= linq.from(list).sum("$.SHJDRC");
          sums[12] = linq.from(list).sum("$.ZXSJDRC");
          sums[13]= "通过:"+linq.from(list).where("$.审核状态=='通过'").count();
            sums[13] += ",不通过:"+linq.from(list).where("$.审核状态=='不通过'").count();
            sums[13] += ",待审核:"+linq.from(list).where("$.审核状态=='待审核'").count();
       return sums;
      //
    },
     async check(array,list){
      return new Promise(async (resolve,reject)=>{
       resolve();       //
       
      });
    },
    async fetchData() {
      var user = getUser();
      var datas = await getJnjd(user.XXID,user.CJPC);
      return datas;
    },
    onadd(model){
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
      
          console.log(JSON.stringify(temp));
          var model = await addJnjd(temp);
          resolve(model);
      })
    },
    
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateJnjd(temp);
          resolve(model);
      })
      //
    },
    async  bulkAdd(array){
       await  bulkAddJnjd({Jnjd:array});
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
        
         await deleteJnjd(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>